x=["key" => "value"]. How does it work in Ruby?

Posted by Earlz on Stack Overflow See other posts from Stack Overflow or by Earlz
Published on 2010-05-15T01:43:19Z Indexed on 2010/05/15 1:54 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

Ok, so I was comparing some stuff in my own DSL to Ruby. One construct they both support is this

x=["key" => "value"]

Knowing the difference between arrays and hashes, I would think this to be illegal, but the result in Ruby is

[{"key" => "value"}]

Why is this? And with this kinda syntax why can't you do

x=("key" => "value") 

Why is an array a special case for implicitly created hashes?

© Stack Overflow or respective owner

Related posts about arrays

Related posts about hash